package com.ljz.controller;

import com.ljz.dao.CustomerRepository;
import com.ljz.entity.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by jiazhang on 2017/4/12.
 */

@RestController
public class CustomerController {

    @Autowired
    CustomerRepository customerRepository;

    /**
     * 查找全部信息
     * @return
     */
    @GetMapping(value = "/customer")
    private List<Customer> customerList() {
        return customerRepository.findAll();
    }


    /**
     * 添加信息
     * @param csex
     * @param cname
     * @param cphone
     * @param caddress
     * @return
     */
    @PostMapping(value = "/customer")
    public Customer addCustomerMessage(@RequestParam("csex") String csex,
                                       @RequestParam("cname") String cname,
                                       @RequestParam("cphone") String cphone,
                                       @RequestParam("caddress") String caddress) {
        Customer customer = new Customer();
        customer.setCsex(csex);
        customer.setCadress(caddress);
        customer.setCname(cname);
        customer.setCphone(cphone);

        return customerRepository.save(customer);
    }
}
